package com.ruoyi.bcsettings.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bcsettings.domain.ErpMembers;
import com.ruoyi.bcsettings.service.IErpMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/bcsettings/hy")
public class ErpMemberController extends BaseController
{
    @Autowired
    private IErpMemberService erpMemberService;

    /**
     * 查询会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpMembers erpMembers)
    {
        startPage();
        List<ErpMembers> list = erpMemberService.selectErpMemberList(erpMembers);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:export')")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpMembers erpMembers)
    {
        List<ErpMembers> list = erpMemberService.selectErpMemberList(erpMembers);
        ExcelUtil<ErpMembers> util = new ExcelUtil<ErpMembers>(ErpMembers.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(erpMemberService.selectErpMemberById(id));
    }

    /**
     * 新增会员管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:add')")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpMembers erpMembers)
    {
        return toAjax(erpMemberService.insertErpMember(erpMembers));
    }

    /**
     * 修改会员管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:edit')")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpMembers erpMembers)
    {
        return toAjax(erpMemberService.updateErpMember(erpMembers));
    }

    /**
     * 删除会员管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:hy:remove')")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(erpMemberService.deleteErpMemberByIds(ids));
    }
}
